﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SchoolSelfManage.aspx.cs" Inherits="School_Manage_SchoolSelfManage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>学校自建成绩管理</title>
<link href="../../Common/css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../Common/Js/jquery.js"></script>
<script type="text/javascript" src="../../Common/Js/common.js"></script>
<script type="text/javascript" src="../../Common/Js/msg.js"></script>
<script type="text/javascript" src="../../Common/Js/jsUtil.js"></script>
<script type="text/javascript">
var cookieName = "openedSchoolExam";
var openedExamId = null;
var currSchoolYear,currTerm;
function Load()
{
    var yearObj =  document.getElementById('selYear'); 
    if(yearObj != null)
    {   
        currSchoolYear = Number("<%=currSchoolYear%>");
        for(var i = 0; i < yearObj.options.length;i++)
        {
            var option = yearObj.options[i];
            
            if(Number(option.value) == Number("<%=currSchoolYear%>"))
            {
                option.selected  = "selected";
                document.getElementById('txtYear').value = "<%=currSchoolYear%>"; 
            }
            else
                 option.selected  = false;
        }
    }
    
    var termObj =  document.getElementById('selTerm'); 
    if(termObj != null)
    {    
        currTerm = Number("<%=currTerm%>");
        for(var i = 0; i < termObj.options.length;i++)
        {
            var option = termObj.options[i];
            
            if(Number(option.value) == Number("<%=currTerm%>"))
            {
                option.selected  = "selected";
                 document.getElementById('txtTerm').value = "<%=currTerm%>";     
            }
            else
                 option.selected  = false;
        }
    }
    
     //若是没有新建权限 则隐藏按钮
    var obj = document.getElementById('btnCreateExam');
    if(parent.schoolmanage == false)
    {
        obj.style.visibility = "hidden";
    }
    else
    {
        obj.style.visibility = "visible";
    }
  //  GetCookie();
}

//弹出删除窗口---------------------------------------------------------------------删除区域
function ShowDelWindow(row)
{
    //如果已录入数据 则不能删除
    var examId = row.id;
    PageMethods.ValidateIsInputScore(examId,function(succ){
            if(succ > 0)
            {
                showMassgeBox("提示","数据已录入，不能删除此考试",1,null);
            }
            else
            {
                //TODO：判断该行状态，除了新建状态以外都不能删除
                showConfirmBox("删除", "确定删除此次考试?", DelExam, examId);
            }   
        },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });

    
    
}
//删除方法
function DelExam(examId)
{
    if(examId > 0)
    {
        PageMethods.DelSchoolExam(examId,function(succ){
               showMassgeBox("提示","删除考试成功",1,null);
               Bind();
           },function(err){
              showMassgeBox("提示",err._message,1,null);
        });
    }
}

//修改考试弹出窗口-----------------------------------------------------------------修改区域
function ShowUpdateWindow(obj)
{
   InitUpdateWindow(obj);

   ShowPopForm("popTable2", "formTitle2", "修改学校考试");
   showMask();
}
 
//初始化弹出修改考试窗口的值
function InitUpdateWindow(row)
{
    var updateDoc = self.frames['updateExamFrame'].document;
    if(updateDoc == null)
        return;
    
    var name = row.cells[0].innerText;
    var nameObj = updateDoc.getElementById('updateName'); 
    if(nameObj != null)
        nameObj.value = name;
    
    var schoolYear = row.cells[2].schoolYear;//初始化学年
    var yearObj =  updateDoc.getElementById('updateSelYear'); 
    if(yearObj != null)
    {
        for(var i = 0; i < yearObj.options.length;i++)
        {
            var option = yearObj.options[i];
            
            if(Number(option.value) == Number(schoolYear))
                option.selected  = "selected";
            else
                 option.selected  = false;
        }
    }
    
    var term = row.cells[2].id; //初始化学期
    var termObj =  updateDoc.getElementById('updateSelTerm'); 
    if(termObj != null)
    {
        for(var i = 0; i < termObj.options.length;i++)
        {
            var option = termObj.options[i];
            
            if(Number(option.value) == Number(term))
                option.selected  ="selected";
             else
                option.selected  = false;
        }
    }
    
     var grade = row.cells[3].id;//初始化年级
     var gradeObj =  updateDoc.getElementById('updateSelGrade'); 
     if(gradeObj != null)
     {
         for(var i = 0; i < gradeObj.options.length;i++)
         {
            var option = gradeObj.options[i];
            if(Number(option.value) == Number(grade))
                option.selected ="selected";
             else
                option.selected  = false;
         }
     }
     
        

     var classType = row.cells[4].id;//初始化年级
     var classTypeObj =  updateDoc.getElementById('updateSelClassType'); 
     if(classTypeObj != null)
     {
         for(var i = 0; i < classTypeObj.options.length;i++)
         {
             var option = classTypeObj.options[i];
             if(Number(option.value) == Number(classType))
                option.selected ="selected";
             else
                option.selected  = false;
         }
     }
//     if(grade > 10)
//        classTypeObj.style.display = "block";
//     else
//        classTypeObj.style.display = "none";
        
     var div = updateDoc.getElementById('divSubjects');//初始化科目
     if(div != null)
     {
         var checkItems =  div.getElementsByTagName('INPUT'); 
         var examId = row.id;
         PageMethods.GetSubjectsBySchoolExam(examId,function(succ){
                 for(var j=0;j < checkItems.length;j++)
                 {
                     checkItems[j].checked = false;
                 }
                 
                 for(var i=0;i<succ.length;i++)
                 {
                     var subjectId = succ[i]["SubjectID"];
                     for(var j=0;j < checkItems.length;j++)
                     {
                        if(Number(checkItems[j].value) == Number(subjectId))
                        {
                          //  alert(checkItems[j].value+","+subjectId);  
                            checkItems[j].checked = "checked";
         
                        }
                     }
                 }
               },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });
      }
      var table = updateDoc.getElementById('updateExamTable');
      table.setAttribute('examId',examId);
}

//过滤学年 --------------------------------------------------------------------------------下拉框事件
function FilterYearChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtYear').value = value;
}
//过滤学期
function FilterTermChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtTerm').value = value;
}
//过滤年级
function FilterGradeChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtGrade').value = value;
}


//打开考试--------------------------------------------------------------打开考试 以及 设置和获取cookie
function OpenSchoolExamWidow(row)
{
    var name = row.cells[0].innerText;
    var examId = row.id;
    var grade = row.cells[3].id;
    var classType = row.cells[4].id;
    
    var uploade;
    var schoolYear = row.cells[2].schoolYear;
    var term = row.cells[2].id;
    if(schoolYear == currSchoolYear && term == currTerm)
        uploade = 0;//可以上报
    else
        uploade = 1;//不可以上报
 
    var arr = new Array();
    arr.push(examId);
    arr.push(name);
    arr.push(grade);
    arr.push(classType);
    arr.push(uploade);
    showConfirmBox("打开考试", "确定打开此次考试?", OpenExam, arr);
}
function OpenExam(arr)
{
    var nameObj = parent.document.getElementById('txtOpenExam'); 
    if(nameObj != null)
        nameObj.innerText = "打开的考试是："+arr[1];

    SetCookie(arr[0],arr[1],arr[2],arr[3],arr[4]);
    

}

//设置cookie 保存打开的学校考试
function SetCookie(examId,examName,grade,classType,uploade)
{   
    PageMethods.SetCookie2(examId,examName,grade,classType,uploade,function(succ){
            document.getElementById('txtGrade').value = grade;
            document.getElementById('txtExamId').value = examId;
            document.getElementById('txtExamName').value = examName;
            document.getElementById('txtClassType').value = classType;
            document.getElementById('txtCanUpload').value = uploade;
            parent.isExamOpened = examId; 
            parent.canUploadScore = uploade;
            document.getElementById('btnSetCookie').click();
        
    },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });

}
 

////从cookie里获取打开学校考试
//function GetCookie()
//{ 
//    openedExamName = "<%=GetOpenedExamName()%>";
// 
//    var nameObj = parent.document.getElementById('txtOpenExam'); 
//    if(nameObj != null)
//    {
//        if(openedExamName.length > 0)
//            nameObj.innerText = "当前打开的考试是："+openedExamName;
//        else
//            nameObj.innerText = "当前没有打开的考试";
//    }
//}
 
//绑定方法  --------------------------------------------------------------绑定，高亮,弹出窗口 等其他方法区域
function Bind()
{
    document.getElementById('btnBind').click();
}

function Select()
{
    document.getElementById('txtYear').value = document.getElementById('selYear').value;
    document.getElementById('txtTerm').value = document.getElementById('selTerm').value;
    document.getElementById('txtGrade').value = document.getElementById('selGrade').value;
    document.getElementById('btnSelect').click();
}

//弹出添加成绩窗口
function ShowAddWindow()
{
    ShowPopForm("popTable", "formTitle", "新建学校考试");
    showMask();
}

 //关闭遮罩层
function CloseMask(formId)
{
    ClosePopForm(formId,true);
    hideMask();
}

//选中行高亮
function SetHightLight(obj)
{
    if(obj != null) 
        obj.style.backgroundColor = "#fffccf";
        
    var table = document.getElementById('schoolExamTable');
    for(var i =0 ; i < table.rows.length;i++)
    {
        var row = table.rows[i];
        if(row != null && row.rowIndex != obj.rowIndex)
        {
            row.style.backgroundColor = "#ffffff";
        }
    }
}

//验证是否为当前学年学期
function ValidateCurrTermYear(row)
{
    var schoolYear = row.cells[2].schoolYear;
    var term = row.cells[2].id;
    if(Number(schoolYear) == Number("<%=currSchoolYear%>") && Number(term) == Number("<%=currTerm%>"))
        return true;
    else
        return false;
}

function ShowInputWindow(row)
{
    if(ValidateCurrTermYear(row))
         showConfirmBox("提示", "是否要开此考试，并跳转到导入数据页面？", InputScore,row);
    else
        showMassgeBox("提示","不能录入数据，只允许本学年本学期的考试进行录入",1,null);
   
}
//导入数据----------------------------------------------------------------------setCookie2
function InputScore(row)
{
    var name = row.cells[0].innerText;
    var examId = row.id;
    var grade = row.cells[3].id;
    var classType = row.cells[4].id;
    
    var uploade;
    var schoolYear = row.cells[2].schoolYear;
    var term = row.cells[2].id;
    if(schoolYear == currSchoolYear && term == currTerm)
        uploade = 0;//可以上报
    else
        uploade = 1;//不可以上报

    
    PageMethods.SetCookie2(examId,name,grade,classType,uploade,function(succ){
        var nameObj = parent.document.getElementById('txtOpenExam'); 
        parent.isExamOpened = true;
        parent.canUploadScore=uploade;
        if(nameObj != null)
            nameObj.innerText = "打开的考试是："+name;
        
        parent.Navigate(4,"InputScore/Left.aspx");
    },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });
}


function ValidateIsInputScore(id)
{ 
    var num = 0;
    if(examId > 0)
    {
        PageMethods.ValidateIsInputScore(examId,function(succ){
            num = succ
                
        },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });
    }
    return num;
}


</script>
</head>
<body onload="Load();">
<div style="overflow-y:auto;overflow-x:none;height:98%;">
    <form id="form1" runat="server">
      <div class="mainWarp" >
        <div class="pageBody" style="height: 96%;">
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
            </asp:ScriptManager>
                
                   <%-- <input type='text' style="color:#4682B4; font-size:15px;border-right: 0px; border-top: 0px; padding-left: 0px; border-left: 0px; width: 500px; border-bottom: 0px" id="txtOpenExam" readonly/>--%>
                    <ul class="butList">
                    
                    <li>
                         学年：<select id="selYear" onclick="FilterYearChange();">
                                    <%= CommonScore.GetSchoolYearOption()%>
                                </select>
                                 <select id="selTerm" onclick="FilterTermChange();">
                                    <option value="-1">全部</option>
                                    <option value="1">上学期</option>
                                    <option value="2">下学期</option>
                                </select>
                               年级：
                                 <select id="selGrade" onclick="FilterGradeChange();">
                                    <option value="-1" selected="selected">全部</option>
                                        <%= CommonScore.GetGradeOption() %>
                                </select>
                         </li>
                        <li><input type="button" value="查询" onclick="Select();" class="commonBut" /></li> 
                        <li><input type="button" value="新建考试" id="btnCreateExam" style="visibility:hidden;" onclick="if(parent.schoolmanage){ShowAddWindow();}else{showMassgeBox('提示','没有权限新建考试',1,null);}" class="commonBut"/></li>
                    </ul>
               
                <div>
                 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                     <ContentTemplate>
                        <asp:Repeater ID="Repeater1" runat="server">
                                <HeaderTemplate>
                                    <div style="overflow-y:auto;overflow-x:none;height:98%;">
                                     <table id="schoolExamTable" class="useList" style="width: 95%">
                                        <tr>
                                            <th style="text-align: left;padding-left: 5px;">考试名</th>
                                            <th style="text-align: left;padding-left: 5px;">创建时间</th>
                                            <th style="text-align: left;padding-left: 5px;">学年学期</th>
                                            <th style="text-align: left;padding-left: 5px;">年级</th>
                                            <th style="text-align: left;padding-left: 5px;">分科</th>
                                            <th>打开考试</th>
                                            <th style="display:none">成绩录入</th>
                                            <th>操作列</th>
                                        </tr>
                                 </HeaderTemplate>
                                 <ItemTemplate>
                                        <tr id="<%# Eval("RID") %>" style="background-color:<%#CommonScore.GetOpenExamColor(0,currentOpenEXAM,SchoolCookie.ExamType,(int)Eval("RID")) %>" >
                                            <td style="text-align: left;padding-left: 5px;"><%# Eval("Name") %></td>
                                            <td style="text-align: left;padding-left: 5px;"><%# ((DateTime)Eval("CreateDate")).ToShortDateString()%></td>
                                            <td style="text-align: left;padding-left: 5px;" id="<%# Eval("Term")%>" schoolYear="<%# Eval("SchoolYear") %>"><%# Eval("SchoolYear") %><%# ConvertTerm((short)Eval("Term"))%></td>
                                            <td style="text-align: left;padding-left: 5px;" id="<%# Eval("Grade")%>"><%# ConvertGrade((int)Eval("Grade"))%></td>
                                            <td style="text-align: left;padding-left: 5px;" id="<%# Eval("ClassType")%>"><%# ConvertClassType((int)Eval("ClassType"))%></td>
                                            <td><a><img src="<%# CommonScore.OpenExamSrc(0,SchoolCookie.ExamType,currentOpenEXAM,(int)Eval("RID")) %>" alt="打开考试" class="imageBtnStyle" onclick="if(parent.report || parent.schoolmanage){OpenSchoolExamWidow(this.parentElement.parentElement.parentElement);}else{showMassgeBox('提示','您没有权限使用这个功能！',1,null);}" /></a></td>
                                            <td style="display:none"><a><img src="<%# CommonScore.InputScoreSrc(0) %>" alt="成绩录入" class="imageBtnStyle" onclick="if(parent.schoolmanage){ShowInputWindow(this.parentElement.parentElement.parentElement);}"/></a></td>
                                            <td>
                                                <a><img src="../../Common/images/hadle_icon.gif" alt="修改" class="imageBtnStyle" allowUpdate="<%# FindCount(Convert.ToInt32(Eval("RID")))  %>" onclick="if(allowUpdate>0){showMassgeBox('提示','已经有班级提交成绩无法进行修改！',1,null);return;}  if(parent.schoolmanage){ShowUpdateWindow(this.parentElement.parentElement.parentElement);}"  /></a>
                                                <a><img alt="删除" class="imageBtnStyle" src="../../Common/images/delete.jpg" onclick="if(parent.schoolmanage){ShowDelWindow(this.parentElement.parentElement.parentElement);}" /></a>
                                            </td>
                                        </tr>
                                        </ItemTemplate>
                                  <FooterTemplate>
                                        </table></div>
                                  </FooterTemplate>
                            </asp:Repeater>
                       
                     </ContentTemplate>
                     <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
                        <asp:AsyncPostBackTrigger ControlID="btnSetCookie" EventName="Click" />
                        <asp:AsyncPostBackTrigger ControlID="btnSelect" EventName="Click" />
                     </Triggers>
                 </asp:UpdatePanel>
                  <div style="display: none;">
                    <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
                    <asp:Button ID="btnSelect" runat="server"   Text="查询" OnClick="btnSelect_Click" />
                    <asp:Button ID="btnSetCookie" runat="server" Text="btnSetCookie" OnClick="btnSetCookie_Click" />
                    <asp:TextBox ID="txtYear" runat="server" />
                    <asp:TextBox ID="txtTerm" runat="server" />
                    <asp:TextBox ID="txtGrade" runat="server" />
                    <asp:TextBox ID="txtExamId" runat="server" />
                    <asp:TextBox ID="txtExamName" runat="server" />
                    <asp:TextBox ID="txtClassType" runat="server" />
                    <asp:TextBox ID="txtCanUpload" runat="server" />
                  </div>
                </div>
                
                 <%-- 添加局级考试的弹出层 --%>
                    <div id="popTable" class="layoutWarp" style="display: none; width: 400px;">
                        <div class="title">
                            <span id="formTitle">新建学校考试</span> <a title="关闭" onclick="return CloseMask('popTable')">
                                关闭</a>
                        </div>
                        <iframe src="CreateSchoolExam.aspx"  id="createExamFrame" width="100%" height="300px" style="overflow:hidden;" frameborder="0"   ></iframe>
                        
                      </div>
                <%-- 修改局级考试弹出层 --%>
                <div id="popTable2" class="layoutWarp" style="display: none; width: 400px;">
                        <div class="title">
                            <span id="formTitle2">修改学校考试</span> <a title="关闭" onclick="return CloseMask('popTable2')">
                                关闭</a>
                        </div>
                        <iframe id="updateExamFrame" width="100%" height="300px" style="overflow:hidden;" src="UpdateSchoolExam.aspx" frameborder="0"></iframe>
               </div>
               
            </div>
          </div>
    </form>
    </div>
</body>
</html>
